package com.itheima.controller;

import com.itheima.entity.ProjectFundingApplication;
import com.itheima.result.PageResult;
import com.itheima.service.IProjectFundingApplicationService;
import com.itheima.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 项目资金申请Controller
 *
 * @author
 * @date 2025-03-20
 */
@RestController
@RequestMapping("/projectFunding")
public class ProjectFundingApplicationController {

    @Autowired
    private IProjectFundingApplicationService projectFundingApplicationService;

    /**
     * 查询项目资金申请列表
     */
    @GetMapping("/list")
    public Result<PageResult> fundingApplicationList(ProjectFundingApplication projectFundingApplication) {
        PageResult pageResult = projectFundingApplicationService.selectProjectFundingApplicationList(projectFundingApplication);
        return Result.success(pageResult);
    }

    /**
     * 获取单个项目资金申请详细信息
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(projectFundingApplicationService.selectProjectFundingApplicationById(id));
    }

    // 根据项目id查询项目资金申请信息
    @GetMapping("/info")
    public Result getInfoByProjectId(@RequestParam Long id) {
        return Result.success(projectFundingApplicationService.selectProjectFundingApplicationByProjectId(id));
    }


    /**
     * 新增项目资金申请
     */
    @PostMapping
    public Result add(@RequestBody ProjectFundingApplication projectFundingApplication) {
        return Result.success(projectFundingApplicationService.insertProjectFundingApplication(projectFundingApplication));
    }

    /**
     * 修改项目资金申请
     */
    @PutMapping
    public Result edit(@RequestBody ProjectFundingApplication projectFundingApplication) {
        return Result.success(projectFundingApplicationService.updateProjectFundingApplication(projectFundingApplication));
    }

    /**
     * 删除项目资金申请
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return Result.success(projectFundingApplicationService.deleteProjectFundingApplicationById(id));
    }
}
